<?php
defined('IN_PHPCMS') or exit('No permission resources.');
pc_base::load_app_class('admin','admin',0);
define('TASK_IMG_PATH','http://image.bigtv.com.cn/images/go3ccms/');
class boneDatabase extends admin
{

    public function __construct()
    {
        pc_base::load_app_func('global');
        require_once PHPCMS_PATH . 'phpcms/libs/PHPExcel.php';
        parent::__construct();
        //获取当前用户信息
        $userid = $_SESSION['userid'];
        $this->spid_db = pc_base::load_model('admin_model');
        $this->db = pc_base::load_model('admin_model');
        $this->current_spid = $this->spid_db->get_one(array('userid' => $userid));
        $this->hospitalinfo = pc_base::load_model('bone_hospitalinfo_model');
        $this->medical_record = pc_base::load_model('bone_medical_record_model');
        $this->patients_info = pc_base::load_model('bone_patients_info_model');
    }

       
        //病人列表
    public function patients_info() {
           //显示当前登陆用户的信息，--start--
        $userid = $_SESSION['userid'];
        $info = $this->db->get_one(array('userid'=>$userid));
         extract($info); 
         //显示当前登陆用户的信息，--end-- 
       $this->patients_info = pc_base::load_model('bone_patients_info_model');
    
        $age=trim($_GET['age']);
        $age1=trim($_GET['age1']);
        $sex=trim($_GET['sex']);
        $anykind=trim($_GET['anykind']);
        // $clinic_time=trim($_GET['clinic_time']);
        // $clinic_time1=trim($_GET['clinic_time1']);
        $where = "1 ";
     
        if(!empty($age)){
            $where.=" and age between '$age' and '$age1' ";
        }
        if(!empty($sex)){
            $where.=" and sex ='$sex' ";
        }
        // if(!empty($clinic_time)){
        //     $where.=" and clinic_time between '$clinic_time' and '$clinic_time1' ";
        // }
        // if(!empty($anykind)){
        //     $where.=" and  archives_num='$anykind' or patient_name ='$anykind' or m.hospital_num ='$anykind' ";
        // }
          if(!empty($anykind)){
            $where.=" and  archives_num='$anykind' or patient_name ='$anykind'  ";
        }

       

        // $field      = 'p.*,m.*';
         $field      = '*';
        //$sql        = "patients_info  WHERE ".$where.$order;
        // $sql        = "patients_info as p left join medical_record as m on m.patients_id=p.id  WHERE ".$where.$order;
        $sql        = "patients_info   WHERE ".$where;
        $order      = 'order by id desc ';
      

        $perpage    = isset($_GET['perpage']) && intval($_GET['perpage']) ? intval($_GET['perpage']) : 15;
        $page       = isset($_GET['page'])    && intval($_GET['page'])    ? intval($_GET['page'])    : 1;
        $totalnum   = $this->patients_info->mynum($sql);
        $totalpage  = $this->patients_info->mytotalpage($sql, $perpage);
        $data       = $this->patients_info->mylistinfo($field, $sql, $order, $page, $perpage);
        // echo "<pre>";
        // var_dump($data);die;
        $multipage  = $this->patients_info->pages;
       
        include $this->admin_tpl('patients_info_show');

    }
       
//添加病人
    public function patients_add(){
           //显示当前登陆用户的信息，--start--
        $userid = $_SESSION['userid'];
        $info = $this->db->get_one(array('userid'=>$userid));
        extract($info);
         //显示当前登陆用户的信息，--end--  
        $this->patients_info = pc_base::load_model('bone_patients_info_model');
        $hospital_data= $this->hospitalinfo->select(1, '*', '', 'id ASC');
        if(isset($_POST['dosubmit'])){
            $patients_num=$this->patients_info->select(1, 'count(*)', '', 'id ASC');
            $patients_id=$patients_num[0]['count(*)'] +1;
            $archives_num=trim($_POST['hospital_id']).'-'.$patients_id;
            $age = date("Y")-$_POST['birthday'];
           if($age<0){
               showmessage(L('病人出生日期大于当前时间'),'?m=admin&c=boneDatabase&a=patients_add');
           }

            $data = array(
                'archives_num' =>$archives_num,
                'patient_name' =>trim($_POST['patient_name']),
                'hospital_id'=>trim($_POST['hospital_id']),
                'sex'         =>trim($_POST['sex']),
                'birthday'    =>trim($_POST['birthday']),
                'age'         =>$age,
                'marriage'    =>trim($_POST['marriage']),
                'nation'      =>trim($_POST['nation']),
                'province'=>trim($_POST['province']),
                'city'=>trim($_POST['city']),
                'county'=>trim($_POST['county']),
                'address'        =>trim($_POST['address']),
                'job'            =>trim($_POST['job']),
                'phone'          =>trim($_POST['phone']),
                'email'          =>trim($_POST['email']),
                'create_time'    =>date("Y-m-d H:i:s"),
                'status'         =>"1"
            );
            $this->patients_info->insert($data);
            $patients_data = $this->patients_info->get_one(array('archives_num'=>$archives_num));
            showmessage(L('operation_success'),'?m=admin&c=boneDatabase&a=patients_edit&id='. $patients_data['id']);
        }else{

            include $this->admin_tpl('patients_add');
        }                       
    }
    public function check_birthday_ajx(){
        $this->patients_info = pc_base::load_model('bone_patients_info_model');
        $birthday = isset($_GET['birthday']) && trim($_GET['birthday']) ? trim($_GET['birthday']) : exit(0);
        $d= date("Y-m-d");
        $age = (strtotime($d)-strtotime($birthday))/(60*60*24);
        if($age<0){
            exit('0');
        }
        exit('1');
    }
    public function check_archives_num_ajx(){
        $this->patients_info = pc_base::load_model('bone_patients_info_model');
        $archives_num = isset($_GET['archives_num']) && trim($_GET['archives_num']) ? trim($_GET['archives_num']) : exit(0);
        $patients_id = isset($_GET['patients_id']) && trim($_GET['patients_id']) ? trim($_GET['patients_id']) : '0';
        $a=$this->patients_info->get_one(array('archives_num'=>$archives_num),'id');

        if ($a){
            if($a['id'] == $patients_id){
                exit('1');
            }else
                exit('0');
        }
        exit('1');
}
//到达编辑病人信息界面
    public function patients_edit(){
        //显示当前登陆用户的信息，--start--
        $userid = $_SESSION['userid'];
        $info = $this->db->get_one(array('userid'=>$userid));
        extract($info);
         //显示当前登陆用户的信息，--end--  
        $id = $_GET['id'];
        $hospital_data= $this->hospitalinfo->select(1, '*', '', 'id ASC');
         $this->patients_info = pc_base::load_model('bone_patients_info_model');
         $this->medical_record = pc_base::load_model('bone_medical_record_model');
         $patients_id="patients_id=".$id;
         $medical_record_data= $this->medical_record->select($patients_id, '*', '', 'patients_id ASC');

        $patients_data = $this->patients_info->get_one(array('id'=>$id));
        include $this->admin_tpl('patients_edit');
    }
//编辑病人信息
    public function patients_editdo(){
        $this->patients_info = pc_base::load_model('bone_patients_info_model');
        if(isset($_POST['dosubmit'])){
            $id= $_POST['id'];
            $archives_num=trim($_POST['hospital_id']).'-'.$id;
            $age = date("Y")-$_POST['birthday'];
            if($age<0){
                showmessage(L('病人出生日期大于当前时间'),'?m=admin&c=boneDatabase&a=patients_add');
            }

            $data = array(
                'archives_num' =>$archives_num,
                'patient_name' =>trim($_POST['patient_name']),
                'hospital_id'=>trim($_POST['hospital_id']),
                'sex'         =>trim($_POST['sex']),
                'birthday'    =>trim($_POST['birthday']),
                'age'         =>$age,
                'marriage'    =>trim($_POST['marriage']),
                'nation'      =>trim($_POST['nation']),
                'province'=>trim($_POST['province']),
                'city'=>trim($_POST['city']),
                'county'=>trim($_POST['county']),
                'address'        =>trim($_POST['address']),
                'job'            =>trim($_POST['job']),
                'phone'          =>trim($_POST['phone']),
                'email'          =>trim($_POST['email']),
                'update_time'    =>date("Y-m-d H:i:s")
            );
          
            $this->patients_info->update($data,array('id'=>$id));

            $msg = '操作成功!';
           showmessage(L('operation_success'),'?m=admin&c=boneDatabase&a=patients_info');
        }else{
            include $this->admin_tpl('patients_edit');
        }
    }
//到达查看病人信息界面
    public function patients_view(){
        //显示当前登陆用户的信息，--start--
        $userid = $_SESSION['userid'];
        $info = $this->db->get_one(array('userid'=>$userid));
        extract($info);
         //显示当前登陆用户的信息，--end--  
        $id = $_GET['id'];
         $this->patients_info = pc_base::load_model('bone_patients_info_model');
         $this->medical_record = pc_base::load_model('bone_medical_record_model');
         $patients_id="patients_id=".$id;
         $medical_record_data= $this->medical_record->select($patients_id, '*', '', 'patients_id ASC');
         // echo "<pre>";
         // var_dump($medical_record_data);echo "<pre/>";die;
        $patients_data = $this->patients_info->get_one(array('id'=>$id));
    
        include $this->admin_tpl('patients_view');
    }
//删除病人
   public function patients_info_delete(){
         $this->patients_info = pc_base::load_model('bone_patients_info_model');
        $this->medical_record = pc_base::load_model('bone_medical_record_model');
        $id = $_GET['id'];
        if(empty($id)){
            $msg = '操作失败!';
            showmessage($msg,'?m=admin&c=boneDatabase&a=patients_info&pc_hash='.$_SESSION['pc_hash'], $ms = 500);
        }else{
        
            //删除操作
            $this->patients_info->update(array('status'=>"2"),array('id'=>$id));
            $this->medical_record->delete(array('status'=>"2"),array('patients_id'=>$id));
            $msg = '操作成功!';
            showmessage($msg,'?m=admin&c=boneDatabase&a=patients_info&pc_hash='.$_SESSION['pc_hash'], $ms = 500);
        }
   }
   //多项删除
public function patients_info_deleteAll(){
         $this->medical_record = pc_base::load_model('bone_medical_record_model');
        $this->patients_info = pc_base::load_model('bone_patients_info_model');
        $ids=explode(',', $_GET['id']);
        foreach ($ids as $v){
            $this->patients_info->update(array('status'=>"2"),array('id'=>$v));
            $this->medical_record->update(array('status'=>"2"),array('patients_id'=>$v));
        }
       
        showmessage('操作成功',base64_decode($_GET['goback']));
}
//添加病历
    public function medicalRecord_add(){
           //显示当前登陆用户的信息，--start--
        $userid = $_SESSION['userid'];
        $info = $this->db->get_one(array('userid'=>$userid));
        extract($info);
         //显示当前登陆用户的信息，--end--
        $this->patients_info = pc_base::load_model('bone_patients_info_model');
        $this->hospitalinfo = pc_base::load_model('bone_hospitalinfo_model');
        $this->medical_record = pc_base::load_model('bone_medical_record_model');
        if(isset($_POST['dosubmit'])){
            $archives_num =trim($_POST['hospital_num']).'-'.$_POST['patients_id'];
            $this->patients_info->update(array('archives_num'=>$archives_num),array('id'=>$_POST['patients_id']));
            $data = array(
                'patients_id'  =>$_POST['patients_id'],
                'clinic_time' =>trim($_POST['clinic_time']),
                'hospital_num' =>trim($_POST['hospital_num']),
                'chief_complaint'=>trim($_POST['chief_complaint']),
                'previous_history'=>trim($_POST['previous_history']),
                'previous_history_desc'=>trim($_POST['previous_history_desc']),
                'family_history'  =>trim($_POST['family_history']),
                'family_history_desc'=>trim($_POST['family_history_desc']),
                'allergic_history' =>trim($_POST['allergic_history']),
                'allergic_history_desc'=>trim($_POST['allergic_history_desc']),
                'drug_use'         =>trim($_POST['drug_use']),
                'drug_use_reason'  =>trim($_POST['drug_use_reason']),
                'drug_name'        =>trim($_POST['drug_name']),
                'use_way'          =>trim($_POST['use_way']),
                'start_time'       =>trim($_POST['start_time']),
                'western_diagnose' =>trim($_POST['western_diagnose']),
                'chinese_diagnose' =>trim($_POST['chinese_diagnose']),
                'height'           =>trim($_POST['height']),
                'weight'           =>trim($_POST['weight']),
                'body_temperature' =>trim($_POST['body_temperature']),
                'heart_rate'       =>trim($_POST['heart_rate']),
                'heart_rhythm'     =>trim($_POST['heart_rhythm']),
                'breath'           =>trim($_POST['breath']),
                'sitting_blood_pressure'=>trim($_POST['sitting_blood_pressure']),
                'leftarm_blood_pressure'=>trim($_POST['leftarm_blood_pressure']),
                'X_ray'             =>trim($_POST['X_ray']),
                'X_ray_hipjoint'    =>trim($_POST['X_ray_hipjoint']),
                'X_raylink'         =>trim($_POST['X_raylink']),
                'X_raydesc'         =>trim($_POST['X_raydesc']),
                'CT'                =>trim($_POST['CT']),
                'CT_link'           =>trim($_POST['CT_link']),
                'CT_hipjoint'       =>trim($_POST['CT_hipjoint']),
                'CT_desc'           =>trim($_POST['CT_desc']),
                'MRI'               =>trim($_POST['MRI']),
                'MRI_hipjoint'      =>trim($_POST['MRI_hipjoint']),
                'MRI_link'          =>trim($_POST['MRI_link']),
                'MRI_desc'          =>trim($_POST['MRI_desc']),
                'create_time'    =>date("Y-m-d H:i:s")
            );
            // var_dump($data);die;
            $this->medical_record->insert($data);
            $patients_data= $this->medical_record->get_one(array('clinic_time'=>trim($_POST['clinic_time'])));
            $medical_id=$patients_data['id'];
            showmessage(L('operation_success'),'?m=admin&c=boneDatabase&a=medicalRecord_edit&id='.$medical_id);
            //showmessage(L('operation_success'),'?m=admin&c=boneDatabase&a=patients_info');
        }else{

            $patients_id= $_GET['patients_id'];
            $idd="patients_id=".$patients_id;
            $data= $this->medical_record->select($idd, '*', '', 'id ASC');
            $hospital_data= $this->hospitalinfo->select(1, '*', '', 'id ASC');
            $patients_data= $this->patients_info->get_one(array('id'=>$patients_id));
            include $this->admin_tpl('medicalRecord_add');
        }                       
    }
    //编辑病历
    public function medicalRecord_edit(){
        //显示当前登陆用户的信息，--start--
        $userid = $_SESSION['userid'];
        $info = $this->db->get_one(array('userid'=>$userid));
        extract($info);
         //显示当前登陆用户的信息，--end--
        $this->hospitalinfo = pc_base::load_model('bone_hospitalinfo_model');
        $hospital_data= $this->hospitalinfo->select(1, '*', '', 'id ASC');
         $this->patients_info = pc_base::load_model('bone_patients_info_model');
         $this->medical_record = pc_base::load_model('bone_medical_record_model');
         //得到病历的id

        $idd="id=".$_GET['id'];   
         $data= $this->medical_record->select($idd, '*', '', 'patients_id ASC');
        
         foreach ($data as $v ) {
             $patients_id=$v['patients_id'];
         }
          //得到病人的id
        $idd="id=".$patients_id; 
        $patients_data= $this->patients_info->select($idd, '*', '', 'id ASC');
        $idd="patients_id=".$patients_id;
        $data= $this->medical_record->select($idd, '*', '', 'id ASC');
        // echo "<pre>";
        // var_dump($data);die;

        $medical_record_data = $this->medical_record->get_one(array('id'=>$_GET['id']));
        //兼用药
        $drug_use = array();
        $drug_use_reason = empty($medical_record_data['drug_use_reason'])? array():split(',',$medical_record_data['drug_use_reason']);
        $drug_name = empty($medical_record_data['drug_name'])? array():split(',',$medical_record_data['drug_name']);
        $use_way    =empty($medical_record_data['use_way'])? array():split(',',$medical_record_data['use_way']);
        $start_time =empty($medical_record_data['start_time'])? array():split(',',$medical_record_data['start_time']);
        for($i=0;$i<count($drug_use_reason);$i++){
            $drug_use[$i] = array(
                    "drug_use_reason"=>$drug_use_reason[$i],
                    "drug_name"=>$drug_name[$i],
                    "use_way"   =>$use_way[$i],
                    "start_time"=>$start_time[$i]
            );
        }
        //x片
        $X_rayAll = array();
        $X_ray = empty($medical_record_data['X_ray'])? array():split(',',$medical_record_data['X_ray']);
        $X_ray_hipjoint = empty($medical_record_data['X_ray_hipjoint'])? array():split(',',$medical_record_data['X_ray_hipjoint']);
        $X_raylink    =empty($medical_record_data['X_raylink'])? array():split(',',$medical_record_data['X_raylink']);
        $X_raydesc =empty($medical_record_data['X_raydesc'])? array():split(',',$medical_record_data['X_raydesc']);
        for($i=0;$i<count($X_ray);$i++){
            $X_rayAll[$i] = array(
                    "X_ray"=>$X_ray[$i],
                    "X_ray_hipjoint"=>$X_ray_hipjoint[$i],
                    "X_raylink"   =>$X_raylink[$i],
                    "X_raydesc"=>$X_raydesc[$i]
            );
        }
        //CT片
        $CTAll = array();
        $CT = empty($medical_record_data['CT'])? array():split(',',$medical_record_data['CT']);
        $CT_hipjoint = empty($medical_record_data['CT_hipjoint'])? array():split(',',$medical_record_data['CT_hipjoint']);
        $CTlink    =empty($medical_record_data['CT_link'])? array():split(',',$medical_record_data['CT_link']);
        $CTdesc =empty($medical_record_data['CT_desc'])? array():split(',',$medical_record_data['CT_desc']);
        for($i=0;$i<count($CT);$i++){
            $CTAll[$i] = array(
                    "CT"=>$CT[$i],
                    "CT_hipjoint"=>$CT_hipjoint[$i],
                    "CTlink"   =>$CTlink[$i],
                    "CTdesc"=>$CTdesc[$i]
            );
        }
         //MRI片
        $MRIAll = array();
        $MRI = empty($medical_record_data['MRI'])? array():split(',',$medical_record_data['MRI']);
        $MRI_hipjoint = empty($medical_record_data['MRI_hipjoint'])? array():split(',',$medical_record_data['MRI_hipjoint']);
        $MRIlink    =empty($medical_record_data['MRI_link'])? array():split(',',$medical_record_data['MRI_link']);
        $MRIdesc =empty($medical_record_data['MRI_desc'])? array():split(',',$medical_record_data['MRI_desc']);
        for($i=0;$i<count($MRI);$i++){
            $MRIAll[$i] = array(
                    "MRI"=>$MRI[$i],
                    "MRI_hipjoint"=>$MRI_hipjoint[$i],
                    "MRIlink"   =>$MRIlink[$i],
                    "MRIdesc"=>$MRIdesc[$i]
            );
        }


        include $this->admin_tpl('medicalRecord_edit');
    }

 public function medicalRecord_editdo(){
     $userid = $_SESSION['userid'];
        $info = $this->db->get_one(array('userid'=>$userid));
        extract($info);
         //显示当前登陆用户的信息，--end--  
        $this->medical_record = pc_base::load_model('bone_medical_record_model');
       if(isset($_POST['dosubmit'])){
            $medical_id= $_POST['medical_id'];
           $archives_num =trim($_POST['hospital_num']).'-'.$_POST['patients_id'];
           $this->patients_info->update(array('archives_num'=>$archives_num),array('id'=>$_POST['patients_id']));
            $data = array(
                'id'  =>$medical_id,
                'clinic_time' =>trim($_POST['clinic_time']),
                'hospital_num' =>trim($_POST['hospital_num']),
                'chief_complaint'=>trim($_POST['chief_complaint']),
                'previous_history'=>trim($_POST['previous_history']),
                'previous_history_desc'=>trim($_POST['previous_history_desc']),
                'family_history'  =>trim($_POST['family_history']),
                'family_history_desc'=>trim($_POST['family_history_desc']),
                'allergic_history' =>trim($_POST['allergic_history']),
                'allergic_history_desc'=>trim($_POST['allergic_history_desc']),
                'drug_use'         =>trim($_POST['drug_use']),
                'drug_use_reason'  =>trim($_POST['drug_use_reason']),
                'drug_name'        =>trim($_POST['drug_name']),
                'use_way'          =>trim($_POST['use_way']),
                'start_time'       =>trim($_POST['start_time']),
                'western_diagnose' =>trim($_POST['western_diagnose']),
                'chinese_diagnose' =>trim($_POST['chinese_diagnose']),
                'height'           =>trim($_POST['height']),
                'weight'           =>trim($_POST['weight']),
                'body_temperature' =>trim($_POST['body_temperature']),
                'heart_rate'       =>trim($_POST['heart_rate']),
                'heart_rhythm'     =>trim($_POST['heart_rhythm']),
                'breath'           =>trim($_POST['breath']),
                'sitting_blood_pressure'=>trim($_POST['sitting_blood_pressure']),
                'leftarm_blood_pressure'=>trim($_POST['leftarm_blood_pressure']),
                'X_ray'             =>trim($_POST['X_ray']),
                'X_ray_hipjoint'    =>trim($_POST['X_ray_hipjoint']),
                'X_raylink'         =>trim($_POST['X_raylink']),
                'X_raydesc'         =>trim($_POST['X_raydesc']),
                'CT'                =>trim($_POST['CT']),
                'CT_link'           =>trim($_POST['CT_link']),
                'CT_hipjoint'       =>trim($_POST['CT_hipjoint']),
                'CT_desc'           =>trim($_POST['CT_desc']),
                'MRI'               =>trim($_POST['MRI']),
                'MRI_hipjoint'      =>trim($_POST['MRI_hipjoint']),
                'MRI_link'          =>trim($_POST['MRI_link']),
                'MRI_desc'          =>trim($_POST['MRI_desc']),
                'update_time'       =>date("Y-m-d H:i:s")
            );
            // echo "<pre>";
            // var_dump($data);
            // echo "</pre>";
            // die;
            $this->medical_record->update($data,array('id'=>$medical_id));
            
            showmessage(L('operation_success'),'?m=admin&c=boneDatabase&a=medicalRecord_edit&id='.$medical_id);
     }else{
         include $this->admin_tpl('medicalRecord_edit');
     }
 }
    //查询病历
     public function medicalRecord_view(){
        //显示当前登陆用户的信息，--start--
        $userid = $_SESSION['userid'];
        $info = $this->db->get_one(array('userid'=>$userid));
        extract($info);
         //显示当前登陆用户的信息，--end--  

         $this->patients_info = pc_base::load_model('bone_patients_info_model');
         $this->medical_record = pc_base::load_model('bone_medical_record_model');
         //得到病历的id

        $idd="id=".$_GET['id'];   
         $data= $this->medical_record->select($idd, '*', '', 'patients_id ASC');
        
         foreach ($data as $v ) {
             $patients_id=$v['patients_id'];
         }
          //得到病人的id
        $idd="id=".$patients_id; 
        $patients_data= $this->patients_info->select($idd, '*', '', 'id ASC');
        $idd="patients_id=".$patients_id;
        $data= $this->medical_record->select($idd, '*', '', 'id ASC');
        // echo "<pre>";
        // var_dump($data);die;

        $medical_record_data = $this->medical_record->get_one(array('id'=>$_GET['id']));
        //兼用药
        $drug_use = array();
        $drug_use_reason = empty($medical_record_data['drug_use_reason'])? array():split(',',$medical_record_data['drug_use_reason']);
        $drug_name = empty($medical_record_data['drug_name'])? array():split(',',$medical_record_data['drug_name']);
        $use_way    =empty($medical_record_data['use_way'])? array():split(',',$medical_record_data['use_way']);
        $start_time =empty($medical_record_data['start_time'])? array():split(',',$medical_record_data['start_time']);
        for($i=0;$i<count($drug_use_reason);$i++){
            $drug_use[$i] = array(
                    "drug_use_reason"=>$drug_use_reason[$i],
                    "drug_name"=>$drug_name[$i],
                    "use_way"   =>$use_way[$i],
                    "start_time"=>$start_time[$i]
            );
        }
        //x片
        $X_rayAll = array();
        $X_ray = empty($medical_record_data['X_ray'])? array():split(',',$medical_record_data['X_ray']);
        $X_ray_hipjoint = empty($medical_record_data['X_ray_hipjoint'])? array():split(',',$medical_record_data['X_ray_hipjoint']);
        $X_raylink    =empty($medical_record_data['X_raylink'])? array():split(',',$medical_record_data['X_raylink']);
        $X_raydesc =empty($medical_record_data['X_raydesc'])? array():split(',',$medical_record_data['X_raydesc']);
        for($i=0;$i<count($X_ray);$i++){
            $X_rayAll[$i] = array(
                    "X_ray"=>$X_ray[$i],
                    "X_ray_hipjoint"=>$X_ray_hipjoint[$i],
                    "X_raylink"   =>$X_raylink[$i],
                    "X_raydesc"=>$X_raydesc[$i]
            );
        }

          //CT片
        $CTAll = array();
        $CT = empty($medical_record_data['CT'])? array():split(',',$medical_record_data['CT']);
        $CT_hipjoint = empty($medical_record_data['CT_hipjoint'])? array():split(',',$medical_record_data['CT_hipjoint']);
        $CTlink    =empty($medical_record_data['CT_link'])? array():split(',',$medical_record_data['CT_link']);
        $CTdesc =empty($medical_record_data['CT_desc'])? array():split(',',$medical_record_data['CT_desc']);
        for($i=0;$i<count($CT);$i++){
            $CTAll[$i] = array(
                    "CT"=>$CT[$i],
                    "CT_hipjoint"=>$CT_hipjoint[$i],
                    "CTlink"   =>$CTlink[$i],
                    "CTdesc"=>$CTdesc[$i]
            );
        }
         //MRI片
        $MRIAll = array();
        $MRI = empty($medical_record_data['MRI'])? array():split(',',$medical_record_data['MRI']);
        $MRI_hipjoint = empty($medical_record_data['MRI_hipjoint'])? array():split(',',$medical_record_data['MRI_hipjoint']);
        $MRIlink    =empty($medical_record_data['MRI_link'])? array():split(',',$medical_record_data['MRI_link']);
        $MRIdesc =empty($medical_record_data['MRI_desc'])? array():split(',',$medical_record_data['MRI_desc']);
        for($i=0;$i<count($MRI);$i++){
            $MRIAll[$i] = array(
                    "MRI"=>$MRI[$i],
                    "MRI_hipjoint"=>$MRI_hipjoint[$i],
                    "MRIlink"   =>$MRIlink[$i],
                    "MRIdesc"=>$MRIdesc[$i]
            );
        }

        include $this->admin_tpl('medicalRecord_view');
    }
//删除病历
      public function medicalRecord_delete(){
        $this->medical_record = pc_base::load_model('bone_medical_record_model');
        $id = $_GET['id'];
        if(empty($id)){
            $msg = '操作失败!';
            showmessage($msg,'?m=admin&c=boneDatabase&a=patients_info&pc_hash='.$_SESSION['pc_hash'], $ms = 500);
        }else{
        
            //删除操作

            $this->medical_record->delete(array('id'=>$id));
            $msg = '操作成功!';
            
            showmessage($msg,'?m=admin&c=boneDatabase&a=patients_info&pc_hash='.$_SESSION['pc_hash'], $ms = 500);
        }
   }
    //医院信息列表
    public function hospitalinfoList(){
        //显示当前登陆用户的信息，--start--
        $userid = $_SESSION['userid'];
        $info = $this->db->get_one(array('userid'=>$userid));
        extract($info);
        //显示当前登陆用户的信息，--end--


        $where = " 1 ";

        $field      = '*';
        $sql        = "hospitalinfo  WHERE ".$where;
        $order      = 'order by id desc ';


        $perpage    = isset($_GET['perpage']) && intval($_GET['perpage']) ? intval($_GET['perpage']) : 15;
        $page       = isset($_GET['page'])    && intval($_GET['page'])    ? intval($_GET['page'])    : 1;
        $totalnum   = $this->hospitalinfo->mynum($sql);
        $totalpage  = $this->hospitalinfo->mytotalpage($sql, $perpage);
        $data       = $this->hospitalinfo->mylistinfo($field, $sql, $order, $page, $perpage);
        // echo "<pre>";
        // var_dump($data);die;
        $multipage  = $this->hospitalinfo->pages;

        include $this->admin_tpl('hospitalinfoList');

    }

    public function hospitalinfo_add(){
        //显示当前登陆用户的信息，--start--
        $userid = $_SESSION['userid'];
        $info = $this->db->get_one(array('userid'=>$userid));
        extract($info);
        //显示当前登陆用户的信息，--end--
        $this->hospitalinfo = pc_base::load_model('bone_hospitalinfo_model');
        if(isset($_POST['dosubmit'])){

            $data = array(
                'hospitalname' =>trim($_POST['hospitalname']),
                'hospitalnum'=>trim($_POST['hospitalnum']),
                'create_time'    =>date("Y-m-d H:i:s")
            );
            $this->hospitalinfo->insert($data);
            showmessage(L('operation_success'),'?m=admin&c=boneDatabase&a=hospitalinfoList&pc_hash='.$_SESSION['pc_hash'], $ms = 500);
        }else{
            include $this->admin_tpl('hospitalinfo_add');
        }
    }

    public function hospitalinfo_edit(){
        //显示当前登陆用户的信息，--start--
        $userid = $_SESSION['userid'];
        $info = $this->db->get_one(array('userid'=>$userid));
        extract($info);
        //显示当前登陆用户的信息，--end--
        $this->hospitalinfo = pc_base::load_model('bone_hospitalinfo_model');
        if(isset($_POST['dosubmit'])){

            $data = array(
                'hospitalname' =>trim($_POST['hospitalname']),
                'hospitalnum'=>trim($_POST['hospitalnum']),
                'update_time'    =>date("Y-m-d H:i:s")
            );
            $this->hospitalinfo->update($data,array('id'=>$_POST['id']));
            showmessage(L('operation_success'),'?m=admin&c=boneDatabase&a=hospitalinfoList&pc_hash='.$_SESSION['pc_hash'], $ms = 500);
        }else{
            $data=$this->hospitalinfo->get_one(array('id'=>$_GET['id']));
            include $this->admin_tpl('hospitalinfo_edit');
        }
    }
    //hospitalinfo_delete
    public function hospitalinfo_delete(){
        $this->hospitalinfo = pc_base::load_model('bone_hospitalinfo_model');
        $id = $_GET['id'];
        if(empty($id)){
            $msg = '操作失败!';
            showmessage(L('operation_success'),'?m=admin&c=boneDatabase&a=hospitalinfoList&pc_hash='.$_SESSION['pc_hash'], $ms = 500);
        }else{
            //删除操作
            $this->hospitalinfo->delete(array('id'=>$id));
            $msg = '操作成功!';
            showmessage($msg,'?m=admin&c=boneDatabase&a=hospitalinfoList&pc_hash='.$_SESSION['pc_hash'], $ms = 500);
        }
    }
    public function hospitalinfo_deleteAll(){
        $this->hospitalinfo = pc_base::load_model('bone_hospitalinfo_model');
        $ids=explode(',', $_GET['id']);
        foreach ($ids as $v){
            $this->hospitalinfo->delete(array('id'=>$v));
        }

        showmessage('操作成功',base64_decode($_GET['goback']));
    }

    public function check_clinic_time_ajx(){

        $clinic_time = isset($_GET['clinic_time']) && trim($_GET['clinic_time']) ? trim($_GET['clinic_time']) : exit(0);
        $patients_id = isset($_GET['patients_id']) && trim($_GET['patients_id']) ? trim($_GET['patients_id']) : '0';
        $medicalrecord_id = isset($_GET['medicalrecord_id']) && trim($_GET['medicalrecord_id']) ? trim($_GET['medicalrecord_id']) : '0';
        $a=$this->medical_record->get_one(array('clinic_time'=>$clinic_time,'patients_id'=>$patients_id));
        if ($a){
            if($a['id'] == $medicalrecord_id){
                exit('1');
            }else
                exit('0');
        }

        exit('1');
    }
    public function check_hospital_num_ajx(){
        $this->hospitalinfo = pc_base::load_model('bone_hospitalinfo_model');
        $hospital_num = isset($_GET['hospitalnum']) && trim($_GET['hospitalnum']) ? trim($_GET['hospitalnum']) : exit(0);
        $hospital_id = isset($_GET['hospital_id']) && trim($_GET['hospital_id']) ? trim($_GET['hospital_id']) : '0';
        $a=$this->hospitalinfo->get_one(array('hospitalnum'=>$hospital_num),'id');

        if ($a){
            if($a['id'] == $hospital_id){
                exit('1');
            }else
                exit('0');
        }
        exit('1');
    }
    public function check_hospital_name_ajx(){
        $this->hospitalinfo = pc_base::load_model('bone_hospitalinfo_model');
        $hospital_name= isset($_GET['hospitalname']) && trim($_GET['hospitalname']) ? trim($_GET['hospitalname']) : exit(0);
        $hospital_id = isset($_GET['hospital_id']) && trim($_GET['hospital_id']) ? trim($_GET['hospital_id']) : '0';
        $a=$this->hospitalinfo->get_one(array('hospitalname'=>$hospital_name),'id');

        if ($a){
            if($a['id'] == $hospital_id){
                exit('1');
            }else
                exit('0');
        }
        exit('1');
    }


}
?>